package com.example.rabbitmq.dircet.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther:
 * @Description: Direct 一对一消息，接收方
 * @Date: 2019/12/26 18:09
 */
@Configuration
public class DirectRabbitMQConfig {

    // 声明队列 myDirectQueue
    @Bean
    public Queue myDirectQueue() {
        return new Queue("myDirectQueue", true);
    }

    @Bean
    public Queue myDirectQueueResponse() {
        return new Queue("myDirectQueueResponse", true);
    }

    //声明交换机 myDirectExchange
    @Bean
    public DirectExchange myDirectExchange() {
        return new DirectExchange("myDirectExchange");
    }

    // 绑定 队列和交换机，指定匹配键，myDirectRoutingKey
    @Bean
    public Binding bindingDirect() {
        return BindingBuilder.bind(myDirectQueue()).to(myDirectExchange()).with("myDirectRoutingKey");
    }

    // 绑定 队列和交换机，指定匹配键，myDirectRoutingKey
    @Bean
    public Binding bindingDirectResponse() {
        return BindingBuilder.bind(myDirectQueueResponse()).to(myDirectExchange()).with("myDirectRoutingKeyResponse");
    }
}
